<?php

namespace Syrius\Type;

/**
 * Enter description here ...
 * @package    Type
 * @author    Domenico Biancardi <domenico.biancardi@gmail.com>
 * @link    http://code.google.com/p/syrius/
 *
 */
abstract class Temporal extends Type {
    /**
     * Generazione della rappresentazione sql
     */
    public function __toString() {
        $str = $this->type;
        // column definition
        if ($this->serial) {
            $str .= " AUTO_INCREMENT";
        }
        if ($this->null) {
            $str .= " NULL";
        } else {
            $str .= " NOT NULL";
        }
        if ($this->default) {
            $str .= " DEFAULT " . $this->default;
        }
        if ($this->comment) {
            $str .= " COMMENT '" . $this->comment . "'";
        }
        if ($this->column_format) {
            $str .= " COLUMN_FORMAT " . $this->column_format;
        }
        if ($this->storage) {
            $str .= " STORAGE " . $this->storage;
        }

        // index
        if ($this->primary) {
        }
        if ($this->index) {
        }
        if ($this->unique) {
        }
        if ($this->fulltext) {
        }
        /*if ($this -> relation){
        }*/

        return $str;
    }

    /**
     * Ritorna il valore che viene letto da database
     */
    public function _fromDb($input) {
        return date($this -> format, strtotime($input));
    }

    /**
     * Ritorna il valore che verrà inserito a database
     * @todo sistemare la conversione della data
     */
    public function _toDb($input) {
        return $input;
        $date = DateTime::createFromFormat(\Syrius\Config\Config::getDateFormat(), $input);
        if ($date == null)
            return $input;
        return parent::_toDb($date->format($this -> format));
    }

}

?>
